import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default ({
  state: {
    menuList: [], // 菜单列表
		permList: [], // 权限列表

    hasRoutes: false, // 是否配置好了路由

    // 左侧菜单栏当前激活菜单的index
    editableTabsValue: 'Index',
    // 标题栏的内容
		editableTabs: [{
			title: '首页',
			name: 'Index',
		}]

  },
  mutations: {
    setMenuList(state, menus) {
      state.menuList = menus
    },
    setPermList(state, perms) {
      state.permList = perms
    },
    changeRouteStatus(state, hasRoutes) {
      state.hasRoutes = hasRoutes
    },
    // 添加标题栏
    addTab(state, tab) {
      // 用户选择某个菜单后，判断该页是否已经在标题栏存在
			let index = state.editableTabs.findIndex(e => e.name === tab.name)

      // index==-1则说明不存在
			if (index === -1) {
        // 将该页标题添加到标题栏
				state.editableTabs.push({
					title: tab.title,
					name: tab.name,
				});
			}
      // 改变当前激活菜单的index
			state.editableTabsValue = tab.name;
    },

    resetState: (state) => {
			state.menuList = []
			state.permList = []

			state.hasRoutes = false
			state.editableTabsValue = 'Index'
			state.editableTabs = [{
				title: '首页',
				name: 'Index',
			}]
		}



  },
  actions: {

  },
  modules: {

  }
})
